<?php
/*************************************************

文章主模型 - the 
Author: Reload <18-1-4>

*************************************************/
namespace Home\Model;
use Think\Model\RelationModel;
class NewsModel extends RelationModel {
    //查询多条数据 不分页
    public function get_all($map,$field="*",$order){
        $data = $this->where($map)->field($field)->order($order)->select();
        return $data;
    }   
     //查询多条数据 带分页
    public function get_all_page($map,$field="*",$order,$page,$pagenum){
        $data = $this->where($map)->field($field)->order($order)->limit($page,$pagenum)->select();
        return $data;
    }    


    //查询单数据
    public function get_one($map){
        $data = $this->where($map)->find();
        return $data;
    }

    //更新
    public function edit($map,$data){
        $r = $this->where($map)->save($data);
        return $r;
    }

    //添加
    public function add($data){
        $data =M('News')->data($data)->add();
        return $data;
    }

    //统计
    public function count($map=''){
        $count = M('News')->where($map)->count();
        return $count;
    }

    //关联仓库阅读量排序(多条)
    public function jion_read($map,$field,$order,$start,$end){
        $data = M('News')->join('jg_news_house ON jg_news.house_id = jg_news_house.id')->where($map)->field($field)->order('jg_news_house.count_read+jg_news_house.push_read desc')->limit($start,$end)->select();
        return $data;
    }

    //关联仓库阅读量排序（单）
    public function jion_read_one($map,$field){
        $data = M('News')->join('jg_news_house ON jg_news.house_id = jg_news_house.id')->where($map)->field($field)->find();
        return $data;
    }
    

     //评论+1
    function set_comments_int($map){
        $r= $this->where($map)->setInc('count_comments');
        return $r;
    }
    

}